package com.leetcode;

public class L0014 {
    public static void main(String[] args) {
        String[] strs={"flower","flow","flight"};
        int index=0;
        String res="";
        char[] chars = strs[0].toCharArray();
        out:
        while(index<chars.length){
            for(int i=1;i<strs.length;i++){
                if(strs[0].length()>strs[i].length()||chars[index]!=strs[i].charAt(index))
                    break out;
                if(i==strs.length-1){
                    res=res+chars[index];
                }
            }
            index++;
        }
        System.out.println(res);
    }

    public String longestCommonPrefix(String[] strs) {
        if(strs.length==1)
            return strs[0];
        int index=0;
        StringBuilder res = new StringBuilder();
        char[] chars = strs[0].toCharArray();
        out:
        while(index<chars.length){
            for(int i=1;i<strs.length;i++){
                if(index>=strs[i].length() || chars[index]!=strs[i].charAt(index))
                    break out;
                if(i==strs.length-1){
                    res=res.append(chars[index]);
                }
            }
            index++;
        }
        return res.toString();
    }
}
